﻿#region 程序集引用
using System;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
#endregion

namespace Tools
{
    /// <summary>
    /// 验证
    /// </summary>
    public static class Validate
    {
        private static readonly Regex MobileRegex = new Regex(@"^1\d{10}$", RegexOptions.Compiled);
        private static readonly Regex EmailRegex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$", RegexOptions.Compiled);

        /// <summary>
        /// 验证输入字符串是否是11位有效手机号码
        /// </summary>
        /// <param name="strContent">要验证的字符串</param>
        /// <returns>是否为有效手机号码</returns>
        public static bool IsMobile(string strContent)
        {
            return !string.IsNullOrEmpty(strContent) && MobileRegex.IsMatch(strContent);
        }

        public static bool IsEmail(string strContent)
        {
            if (string.IsNullOrWhiteSpace(strContent))
                return false;

            var pattern = @"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$";
            return Regex.IsMatch(strContent, pattern);
        }


    }

}
